package co.fitstart.entity.course.schedule;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.user.Student;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "signin_record")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class SigninRecord {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 是否手机端签到 */
    private boolean mobile;
    
    /** 签到时间 */
    private Date signinTime;
    
    /** 签到备注 */
    private String comment;
    
    /** 学员姓名 冗杂字段*/
    private String studentName;
    
    /** 学员手机 冗杂字段 */
    private String studentMobile;
    
    /** 课程名称 冗杂字段 */
    private String courseName;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Student student;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Principal coach;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private CourseSchedule courseSchedule;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public SigninRecord() {
        
    }
    
    /**
     * 
     * @param courseSchedule
     * @param mobile
     */
    public SigninRecord(CourseSchedule courseSchedule, boolean mobile) {
        this.mobile = mobile;
        this.signinTime = new Date();
        this.comment = courseSchedule.getComment();
        this.studentName = courseSchedule.getStudent().getName();
        this.studentMobile = courseSchedule.getStudent().getMobile();
        this.courseName = courseSchedule.getCourse().getName();
        this.student = courseSchedule.getStudent();
        this.coach = courseSchedule.getCoach();
        this.courseSchedule = courseSchedule;
        this.disabled = false;
    }

    public Date getOccurDate() {
        return courseSchedule.getOccurDate();
    }

    public String getOccurHour() {
        return courseSchedule.getOccurHour();
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the mobile
     */
    public boolean isMobile() {
        return mobile;
    }

    /**
     * @return the signinTime
     */
    public Date getSigninTime() {
        return signinTime;
    }

    /**
     * @return the comment
     */
    public String getComment() {
        return comment;
    }

    /**
     * @return the studentName
     */
    public String getStudentName() {
        return studentName;
    }

    /**
     * @return the studentMobile
     */
    public String getStudentMobile() {
        return studentMobile;
    }

    /**
     * @return the courseName
     */
    public String getCourseName() {
        return courseName;
    }

    /**
     * @return the student
     */
    public Student getStudent() {
        return student;
    }

    /**
     * @return the coach
     */
    public Principal getCoach() {
        return coach;
    }

    /**
     * @return the courseSchedule
     */
    public CourseSchedule getCourseSchedule() {
        return courseSchedule;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(boolean mobile) {
        this.mobile = mobile;
    }

    /**
     * @param signinTime the signinTime to set
     */
    public void setSigninTime(Date signinTime) {
        this.signinTime = signinTime;
    }

    /**
     * @param comment the comment to set
     */
    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * @param studentName the studentName to set
     */
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    /**
     * @param studentMobile the studentMobile to set
     */
    public void setStudentMobile(String studentMobile) {
        this.studentMobile = studentMobile;
    }

    /**
     * @param courseName the courseName to set
     */
    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    /**
     * @param student the student to set
     */
    public void setStudent(Student student) {
        this.student = student;
    }

    /**
     * @param coach the coach to set
     */
    public void setCoach(Principal coach) {
        this.coach = coach;
    }

    /**
     * @param courseSchedule the courseSchedule to set
     */
    public void setCourseSchedule(CourseSchedule courseSchedule) {
        this.courseSchedule = courseSchedule;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
